import axios from 'axios'

const API_URL = '/api/teacher'

/**
 * 教师API服务
 */
class TeacherService {
  /**
   * 获取教师的学生列表
   */
  getMyStudents() {
    return axios.get(`${API_URL}/students`)
  }

  /**
   * 添加学生账号
   */
  addStudent(studentData: any) {
    return axios.post(`${API_URL}/students`, studentData)
  }

  /**
   * 更新学生信息
   */
  updateStudent(studentData: any) {
    return axios.put(`${API_URL}/students/${studentData.id}`, studentData)
  }

  /**
   * 删除学生账号
   */
  deleteStudent(id: number) {
    return axios.delete(`${API_URL}/students/${id}`)
  }

  /**
   * 获取待审核的成果列表
   */
  getPendingAchievements() {
    return axios.get(`${API_URL}/achievements/pending`)
  }

  /**
   * 获取已审核的成果列表
   */
  getReviewedAchievements() {
    return axios.get(`${API_URL}/achievements/reviewed`)
  }

  /**
   * 获取成果详情
   */
  getAchievementById(id: number) {
    return axios.get(`${API_URL}/achievements/${id}`)
  }

  /**
   * 审核成果
   */
  reviewAchievement(reviewData: any) {
    return axios.put(`${API_URL}/achievements/review`, reviewData)
  }

  /**
   * 获取所有成果（教师端用于管理和审核）
   */
  getAllAchievements(params?: { status?: string; type?: string; studentId?: number }) {
    return axios.get('/api/achievements/all', { params })
  }

  /**
   * 获取成果详情（教师端）
   */
  getAchievementDetail(type: string, id: number) {
    return axios.get(`/api/achievements/${type}/${id}`)
  }

  /**
   * 审核成果（新版本）
   */
  approveAchievement(type: string, id: number, data: { status: string; comment?: string }) {
    return axios.put(`/api/achievements/${type}/${id}/review`, data)
  }
}

export default new TeacherService() 